package Global;
import java.util.ArrayList;

import Definitions.GraphClass;
import Statistics.LinksChecker;

/*****************************************************************
* Name : Sum
* Aim : This class aims to keep the global variables *
*****************************************************************/
public class GlobalClass implements Cloneable
{
	/*The array that keeps the classes, initialized in the read operation*/
	public ArrayList <ClassIdentificationClass> classList;
	/*The value that keeps the iteration value in k-fold RS and k times SS*/
	//public int size;

	public int classSize;

	public LinksChecker linksChecker;
	
	public int[] frequencyOfEachClass;
	
	public static class RunningValues
	{
		public static int executionFor;		//For which dataset type we will be running.
		public static int maximumNumberOfCPUCoresToBeUsedForTooMuchRamRequiringAndTimeConsumingTasks;
		public static int maximumNumberOfCPUCoresToBeUsedForNotMuchRamRequiringAndTimeConsumingTasks;
		public static int envType;		//For which dataset type we will be running.
		public static boolean integrityCheckResult;
	}
	
	

	
	//public static ArrayList <Double> classRatiosOfTrain;
	/*Constructor of the class*/
	public GlobalClass() {
		// TODO Auto-generated constructor stub
		classList=new ArrayList <ClassIdentificationClass>();
		//classRatiosOfTrain= new ArrayList <Double>();
		linksChecker = new LinksChecker();
	}
	
	
	/*****************************************************************
	* Name : findRatios
	* Aim : This method aims to calculate the ratios of each class and set the global classList's ratios with these values*
	* Inputs : Graph g *
 	* Outputs :  - *
	* Data Structures : *
	* Algorithms : Firstly this method calculates the number of the nodes in each class then it finds the ratios and does the set operation.*
	*****************************************************************/
	public void findRatios(GraphClass g) 
	{
		//total arraylist will be used to save the total numbers of each class
		ArrayList<Integer> total = new ArrayList<Integer>();
		int size = g.getDataSet().size();
		int order;

		for (int i = 0; i < classList.size(); i++) 
		{
			total.add(0);
		}

		for (int i = 0; i < size; i++) 
		{
			order = g.getDataSet().get(i).getClassOrder();
			total.set(order, total.get(order) + 1);
		}

		//Divide the each class value to size and find the ratios for each class and assign these values in the classList global array
		for (int i = 0; i < classList.size(); i++) 
		{
			classList.get(i).setRatio(
					Double.parseDouble(Integer.toString(total.get(i)))
							/ Double.parseDouble(Integer.toString(size)));
		}
	}
	
	public Object clone()
	{
		GlobalClass another = null;
		try
		{
			another = (GlobalClass) super.clone();
		}
		catch(CloneNotSupportedException e) {e.printStackTrace();} 
		//This exception will not occur
	
		return another;
	}
}
